/*jslint adsafe:false, 
 bitwise: true, 
 browser:true, 
 cap:false, 
 debug:false,
 eqeqeq: true,
 evil: false,
 forin: false,
 fragment:false, 
 laxbreak:false, 
 nomen:true, 
 on:false,
 passfail:false, 
 plusplus:true, 
 rhino:false, 
 undef:true, 
 white:false, 
 widget:false */

/*extern 
 RadioStar, 
 Stations */

/**
 * @memberOf RadioStar.Stations
 * @name BanditRock
 * @static
 * @type object
 * @description Bandit Rock 106,3
 */
RadioStar.Stations.BanditRock = function(Debug, QuickTime) 
{
  // Private Variables
  var that,
  currentState,
  STOPPED = 1, PLAYING = 2, PAUSED = 3, LOADING = 4,
  url = "http://bandit.str.mtgradio.dgcsystems.net/bandit/?MSWMExt=.asf";
  
  // Private methods
  
  
  // Public methods
  return /** @scope BanditRock */ {
    /**
     * @memberOf BanditRock
     * @description Initialization function for BanditRock.
     */
    init: function()
    {
      if(!that)
      {
        that = this;
        currentState = STOPPED;
      }
    },
    
    /**
     * @memberOf BanditRock
     * @function name
     * @description Name of this station.
     */
    name : "Bandit Rock 106,3",
    
    /**
     * @memberOf BanditRock
     * @function playPause
     * @description Starts playing this station. Pauses the playback if playing.
     */
    playPause: function () 
    {
      try
      {
        if(!QuickTime)
        {
          QuickTime = document.getElementById("quicktime");
        }
        
        if(QuickTime)
        {
          if(currentState === PLAYING)
          {
            QuickTime.Stop();
            currentState = PAUSED;
          }
          else if(currentState === PAUSED || currentState === STOPPED)
          {
            if(QuickTime.GetMovieName !== that.name)
            {
              QuickTime.Stop();
              QuickTime.SetMovieName(that.name);
              if(!QuickTime.GetAutoPlay())
              {
                QuickTime.SetAutoPlay(true);
              }
              QuickTime.SetHREF(url);
            }
            else
            {
              QuickTime.Play();
            }
            currentState = PLAYING;
          }
        }
      }
      catch (error)
      {
        Debug.alert("Error in BanditRock.play: " + error);
      }
    },
    
    /**
     * @memberOf BanditRock
     * @function stop
     * @description Stops playing this station.
     * @param {boolean} [withFadeout] If true, fades out the station before stopping.
     */
    stop: function (withFadeout) 
    {
      try
      {
        if(!QuickTime)
        {
          QuickTime = document.getElementById("quicktime");
        }
        
        if(QuickTime)
        {
          if(currentState === PLAYING)
          {
            if(withFadeout)
            {
              // fade out and then stop
            }
            else
            {
              QuickTime.Stop();
            }
          }
          else if(currentState === LOADING)
          {
            // Abort loading?
          }
        }
      }
      catch (error)
      {
        Debug.alert("Error in BanditRock.stop: " + error);
      }
    }
  };
}(EPG.debug, document.getElementById("quicktime"));
RadioStar.Stations.BanditRock.init();
